package com.tool.permission.subject;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.tool.permission.model.Resource;
import com.tool.permission.util.URLMatcher;

public class WebSubject implements Serializable {

	private static final long serialVersionUID = 7328387428234676336L;

	private List<Resource> resources;
	
	private Object userid;
	
	public WebSubject(List<Resource> resources,Object userid) {
		this.resources = resources;
		this.userid = userid;
	}
	/**
	 * 判断是否有权限
	 * @author huff
	 * @date 2016年6月27日
	 * @param permission
	 * @return
	 */
	public boolean isPermitted(String permission) {
		if(CollectionUtils.isEmpty(resources)) return false;
		for (Resource resource : resources) {
			if(URLMatcher.match(resource.getUrl(), permission)) {
				return true;
			}
		}
		return false;
	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public Object getUserid() {
		return userid;
	}

	public void setUserid(Object userid) {
		this.userid = userid;
	}
	
	
	
}
